<% layout('/layouts/default.html', {title: '供应商查询', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('供应商详情')}
                <% if (hasPermi('base:supplier:supplier:edit')){ %>
                    <button type="button" class="btn btn-primary" id="editView">${text('编辑单据')}</button>
                <% } %>
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${supplier}" action="${ctx}/base/supplier/supplier/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('供应商编号')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:hidden path="isNewRecord"/>
                                <#form:input path="supplierId" id="supplierId" maxlength="64" readonly="true" placeholder="自动生成" class="form-control"/>
                            </div>
                        </div>
                    </div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('供应商名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="supplierName" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('供应商类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="supplierType" dictType="erp_supplier_type" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('供应商名称缩写')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="supplierNameAbbreviation" maxlength="100" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('地址信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('国家/省份/城市')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="area" title="${text('选择')}"
                                path="area.areaCode" labelPath="area.areaName" labelValue="${supplier.area.treeNames!}"
                                url="${ctx}/sys/area/treeData" returnFullName="true"
                                class=" required" allowClear="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('港口')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="port" dictType="erp_harbor_list" blankOption="true" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('详细地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="address" maxlength="200" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('工商信息')}</div>
                <div class="ml10 mr10">
                    <table id="supplierBusinessInfoDataGrid"></table>
                </div>
                <div class="form-unit">${text('信用证账户信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('收益行信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="incomeBankInfo" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="creditAccountName" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="creditAccountAddress" maxlength="200" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('swift码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="swiftNumber" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('TT账户信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('户名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="ttAccountName" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('账号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="ttAccountNumber" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('银行名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="ttBankName" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('银行地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="ttBankAddress" maxlength="200" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('计息方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="interestCalculationMethod" dictType="erp_calc_interest" blankOption="true" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('业务类型')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-3" title="">
                                <span class="required hide">*</span> ${text('业务类型')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-9">
                                <#form:select path="businessType" dictType="erp_business_type" multiple="true" blankOption="true" class="form-control" disabled="true" />
                            </div>
                        </div>
                    </div>
                </div>
                <!-- <div class="ml10 mr10">
                    <table id="supplierBusinessTypeDataGrid"></table>
                </div>-->
                <div class="form-unit">${text('联系方式')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-3" title="">
                                <span class="required hide">*</span> ${text('电话')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="phone" maxlength="64" class="form-control" disabled="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-3" title="">
                                <span class="required hide">*</span> ${text('传真')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="fax" maxlength="100" class="form-control" disabled="true"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="ml10 mr10">
                    <table id="supplierContactInfoDataGrid"></table>
                </div>
                <div class="form-unit">${text('资方签约报关行')}</div>
                <div class="ml10 mr10">
                    <table id="supplierCustomBrokerDataGrid"></table>
                </div>
                <div class="form-unit">${text('附件信息')}</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${supplier.id}" bizType="supplier_file"
									uploadType="all" class="" readonly="true" preview="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('系统信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createDate" class="form-control" disabled="true"
								dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<!--<#form:input path="createBy" class="form-control" disabled="true"/>-->
								<#form:select path="createBy" items="${listUser}" disabled="true"
								itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
								dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<!--<#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>-->
								<#form:select path="updateBy" items="${listUser}" disabled="true"
								itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化供应商工商信息DataGrid对象
$("#supplierBusinessInfoDataGrid").dataGrid({
	data:${toJson(supplier.supplierBusinessInfoList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:false, hidden:true},
		{header:'主键', name:'businessInfoId', editable:false, hidden:true},
		{header:'${text("名称")}', name:'businessInfoName', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		/*{header:'${text("是否必填")}', name:'required', width:100,
			editable:true, edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('sys_yes_no')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},*/
        {header:'${text("是否必填")}', name:'required', index:'a.required', width:100, align:"center",
            formatter: function(val, obj, row, act){
                return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, ' ', true);
            }},
		{header:'${text("有效期起")}', name:'validPeriodFrom', width:150, 
			formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:false, edittype:'text', editoptions:{'class':'form-control laydate required', 'readonly':'true',
				dataInit: function(element){
					laydate.render({elem:element, type:'date', format:'yyyy-MM-dd'});
				}
			}
		},
		{header:'${text("有效期至")}', name:'validPeriodTo', width:150, 
			formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:false, edittype:'text', editoptions:{'class':'form-control laydate required', 'readonly':'true',
				dataInit: function(element){
					laydate.render({elem:element, type:'date', format:'yyyy-MM-dd'});
				}
			}
		},
        {header:'${text("文件上传")}', name:'id', align:"center", width:200,
            editable: true, edittype: "custom", editoptions: {
                custom_element: function(val, editOptions) {
                    return js.template('fileuploadTpl', {
                        id: 'fileupload_'+editOptions.id, title: '区域选择',
                        bizKey: val, bizType: 'supplierBusinessInfoData_file', cssClass: ''
                    });
                }
            }
        },
		{header:'${text("供应商ID")}', name:'supplierId.supplierId', editable:false, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#supplierBusinessInfoDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {businessInfoId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'supplierBusinessInfoList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,businessInfoId,businessInfoName,required,validPeriodFrom,validPeriodTo,supplierId.supplierId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
//初始化供应商联系方式DataGrid对象
$("#supplierContactInfoDataGrid").dataGrid({
	data:${toJson(supplier.supplierContactInfoList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:false, hidden:true},
		{header:'主键', name:'contactId', editable:false, hidden:true},
		{header:'${text("姓名")}', name:'contactName', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("职位")}', name:'position', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("电话号码")}', name:'phone', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("电子邮箱")}', name:'email', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("供应商ID")}', name:'supplierId.supplierId', editable:false, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#supplierContactInfoDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {contactId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'supplierContactInfoList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,contactId,contactName,position,phone,email,supplierId.supplierId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
//初始化资方签约报关行DataGrid对象
$("#supplierCustomBrokerDataGrid").dataGrid({
	data:${toJson(supplier.supplierCustomBrokerList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:false, hidden:true},
		{header:'主键', name:'supplierCustomBrokerId', editable:false, hidden:true},
        /*{header:'${text("报关行")}', name:'customBroker', index:'a.custom_broker', width:100, align:"center",
            formatter: function(val, obj, row, act){
                // return js.getJSON(${toJson(supplierList)},val);
                return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, ' ', true);
        }},*/
        {header:'${text("报关行")}', name:'customBroker', width:100,
            editable:false, edittype:'select', editoptions:{'class':'form-control',
                items: ${toJson(supplierList)},
                itemLabel: 'supplierName', itemValue: 'supplierId', dataInit: function(element){
                    $(element).select2().on("change",function(){$(this).resetValid()});
                }
            }
        },
        {header:'${text("供应商ID")}', name:'supplierId.supplierId', editable:false, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#supplierCustomBrokerDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {supplierCustomBrokerId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'supplierCustomBrokerList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,supplierCustomBrokerId,customBroker,supplierId.supplierId,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
</script>
<script id="fileuploadTpl" type="text/template">//<!--<div>
<#form:fileupload id="{{d.id}}" bizKey="{{d.bizKey}}" bizType="{{d.bizType}}"
	uploadType="all" class="{{d.cssClass}}" isMini="true" preview="true"/>
</div>//--></script>
<script>
    $("#editView").click(function () {
        var id = $("#supplierId").val();
        var URL = '${ctx}/base/supplier/supplier/form?supplierId=' + id;
        window.location.href =URL;
    });
</script>
